package com.mtl.bookt.service.impl;

import com.mtl.bookt.domain.BookInfo;
import com.mtl.bookt.mapper.BookInfoMapper;
import com.mtl.bookt.service.IBookInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.mtl.common.tool.model.Page;

import java.util.List;
import java.util.Map;

/**
 *  服务实现类
 *
 * @author lsc
 * @since 2019-07-03
 */
@Service
public class BookInfoServiceImpl implements IBookInfoService {

    @Autowired
    private BookInfoMapper bookInfoMapper;

    @Override
    public BookInfo findById(Integer id) {
        return bookInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<BookInfo> findPage(Map<String,Object> param) {
        int page =(int) param.get("page");
        int size =(int) param.get("size");

        PageHelper.startPage(page,size);
        List<BookInfo> bookInfos=bookInfoMapper.selectPage(param);
        return new Page<>(bookInfos);
    }

    @Override
    public int saveOrUpdate(BookInfo bookInfo) {
        if(bookInfo.getBookId()!=null){
        return bookInfoMapper.updateByPrimaryKey(bookInfo);
        }
        return bookInfoMapper.insert(bookInfo);
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        return bookInfoMapper.deleteByIdList(ids);
    }
}
